package leetcode.day_2020_2021_1_25_2021_1_31;


/**
 * 12. 整数转罗马数字
 * https://leetcode-cn.com/problems/integer-to-roman/
 */
public class LeetCode0012 {
    public static void main(String[] args) {

    }

    public String intToRoman(int num) {
        int[] nums = {1000, 900, 500, 400, 100, 90, 50, 40, 10, 9, 5, 4, 1};
        String[] romNums = {"M", "CM", "D", "CD", "C", "XC", "L", "XL", "X", "IX", "V", "IV", "I"};
        StringBuilder s = new StringBuilder();
        int index = 0;
        while(index < 13) {
            while (num >= nums[index]) {
                s.append(romNums[index]);
                num = num - nums[index];
            }
            index++;
        }
        return s.toString();
    }
}
